package com.wzdigit.wms.wms.controller.TransferWareHouse;

import com.wzdigit.framework.model.response.ErrorEntity;
import com.wzdigit.wms.basic.domain.dtos.inventory.SnInforDto;
import com.wzdigit.wms.basic.client.request.trsn.ScanGoodsSNNewRequest;
import com.wzdigit.wms.basic.client.request.trsn.ScanUpRequest;
import com.wzdigit.wms.basic.client.response.Result;
import com.wzdigit.wms.wms.constant.WmsWareConstant;
import com.wzdigit.wms.wms.service.core.transfer.TransferUpService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;

@RestController
@Api(tags = "转仓单上架(PDA)")
@RequestMapping(value = WmsWareConstant.API_VERSION)
public class TransferUpController {

	private static final String REQUEST_MODEL = "/transferup";

	@Autowired
	private TransferUpService transferUpService;
	
	@ApiOperation(value = "扫描条码", notes = "扫描条码")
	@ApiResponses({ @ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class) })
	@GetMapping(value = REQUEST_MODEL + "/getgoodsinfoNew")
	public List<SnInforDto> getgoodsinfoNew(ScanGoodsSNNewRequest search, HttpServletRequest servletRequest,
			HttpServletResponse servletResponse) {
		try {
			return transferUpService.scanGoodsSNNew(search);
		} catch (Exception ex) {
			servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
			throw ex;
		}
	}

	@ApiOperation(value = "扫描库位上架", notes = "扫描库位上架")
	@ApiResponses({ @ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class) })
	@PostMapping(value = REQUEST_MODEL + "/scanUp")
	public Result<?> scanUp(@Valid @RequestBody ScanUpRequest dto, HttpServletRequest servletRequest,
			HttpServletResponse servletResponse) throws Exception {
		try {
			return transferUpService.scanUp(dto, servletRequest);
		} catch (Exception ex) {
			ex.printStackTrace();
			servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
			throw ex;
		}
	}
}
